package com.teaching.Dao;

import com.teaching.Enity.Learn;
import com.teaching.Enity.Student;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class LearnDaoAchieve implements LearnDao {

    private SqlSession sqlSession;
    private String resource = "mybatis.xml";

    @Override//将选课结果存入数据库
    public void ChooseCourse(Learn learn) throws IOException{
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        sqlSession = sessionFactory.openSession();
        sqlSession.insert("chooseCourse",learn);
        sqlSession.commit();
        sqlSession.close();
    }

    @Override//获取选课结果的编号
    public List<Learn> GetSc_id(Learn learn) throws IOException{
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        sqlSession = sessionFactory.openSession();
        List<Learn> learnList=sqlSession.selectList("getSc_id",learn);
        sqlSession.commit();
        sqlSession.close();
        return learnList;
    }
}
